// components/approval.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    listProps: {}
  },
  observers: {
    'listProps': function (val) {
      console.log(val)
      this.setData({
        listProp: val
      })
      wx.setStorageSync('listProps', JSON.stringify(val))
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    listProps: {},
    manList: [],
    radio: 1,
    showMan: false,
    status: true,
    manList: [],
  },
  created() {},

  /**
   * 组件的方法列表
   */
  methods: {
    setDa(val) {
      this.setData({
        listProp: val
      })
      console.log(this.data);
    },
    getMember() {
      console.log(112);
      var url = app.globalData.url + "member/getMember",
        that = this,
        manList = [],
        listProps = JSON.parse(wx.getStorageSync('listProps'));
      console.log(listProps);
      app.wxRequest(url, {
        departmentId: 0
      }, res => {
        console.log(res);
        if (res.flag) {
          for (var i in res.data.members) {
            for (var j in listProps['topList']) {
              if (res.data.members[i].member_id != listProps['topList'][j].memberId) {
                manList.push(res.data.members[i])
              }
            }
          }
          console.log(manList);
          that.setData({
            manList,
            listProps
          })
        }
      })
    },
    addDataChicken(e) {
      var item = e.currentTarget.dataset.obj,
        index = e.currentTarget.dataset.index,
        listProps = this.data.listProps,
        radio = this.data.radio,
        manList = this.data.manList,
        that = this;
      console.log(item);
      console.log(index);
      console.log(listProps);
      if (listProps.readonlyStatus) {
        return false
      }
      radio = item.member_id;
      item.memberName = item.member_name;
      item.memberId = item.member_id;
      item.del = true;
      listProps['topList'].push(item);
      that.setData({
        listProps,
        radio,
      })
      wx.setStorageSync('listProps', JSON.stringify(listProps))
      that.triggerEvent('changeHandle', item)
      setTimeout(() => {
        manList.splice(index, 1);
        that.setData({
          manList,
          showMan: false
        })
      }, 200)
    },
    showManData() {
      var listProps = JSON.parse(wx.getStorageSync('listProps')),
        status = this.data.status;
      if (listProps.readonlyStatus) {
        return false
      }
      if (listProps['topList'].length > 3) {
        wx.showToast({
          title: '已达到人数上限',
          icon: 'none'
        })
        return false
      }
      if (status) {
        this.setData({
          status: false
        })
        this.getMember();
      }
      this.setData({
        showMan: true
      })
    },
    delDataChicken(e) {
      var index = e.currentTarget.dataset.index,
        listProps = JSON.parse(wx.getStorageSync('listProps')),
        manList = this.data.manList,
        status = this.data.status;
      console.log(index);

      if (listProps.readonlyStatus) {
        return false
      }
      if (listProps['topList'].length == 1) {
        return false
      }
      manList.push(listProps['topList'][index]);
      listProps['topList'].splice(index, 1);
      this.setData({
        radio: 1,
        manList,
        listProps
      })
      console.log(listProps['topList'])

    },
    popClose() {
      this.setData({
        radio: 1,
        showMan: false
      })
    },
  },

})